//
//  BBHelpListCell.swift
//  BBLinkiOSProject
//
//  Created by liuzhu on 2018/12/29.
//  Copyright © 2018 liuzhu. All rights reserved.
//

import UIKit

class BBHelpListCell: UITableViewCell {

    var help:BBHelp?{
        didSet{
            timeLabel.text = BBUtils.timeStampToString(timeStamp: Int(truncating: (help?.updateTime)!))
            if help?.status == nil || Int(truncating: (help?.status)!) == 0{
                statusLabel.textColor = UIColor.darkGray
                statusLabel.text = "Submitted"
            }else if(Int(truncating: (help?.status)!) == 1){
                statusLabel.text = "Received order"
                statusLabel.textColor = UIColor.green
            }else if(Int(truncating: (help?.status)!) == 2){
                statusLabel.text = "Done"
                statusLabel.textColor = UIColor.green
            }else{
                 statusLabel.textColor = UIColor.lightGray
                 statusLabel.text = "End"
            }
            contentLabel.text = help?.helpDes
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        //必须加入的方法
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        contentView.addSubview(titleView)
        contentView.addSubview(contentLabel)
        contentLabel.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: titleView, size: nil, offset: CGPoint(x: 10, y: 0))
        contentLabel.xmg_AlignInner(type: XMG_AlignType.BottomRight, referView: contentView, size: nil, offset: CGPoint(x: 0, y: 0))
    }
    
    private lazy var titleView:UIView = {
        let iv = UIView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 30))
        iv.backgroundColor = UIColor.init(red: 240/255.0, green: 240/255.0, blue: 240/255.0, alpha: 1)
        iv.addSubview(timeLabel)
        iv.addSubview(statusLabel)
        return iv
    }()
    
    public lazy var timeLabel:UILabel = {
        let timeLable = UILabel(frame: CGRect(x: 10, y: 0, width: ((UIScreen.main.bounds.size.width-20)/3)*2, height: 30))
        timeLable.textColor = UIColor.lightGray
        timeLable.font = UIFont.systemFont(ofSize: 13)
        timeLable.textAlignment = NSTextAlignment.left
        return timeLable
    }()
    
    public lazy var statusLabel:UILabel = {
       let statusLabel = UILabel(frame: CGRect(x: ((UIScreen.main.bounds.size.width)/3)*2 + 10, y: 0, width: (UIScreen.main.bounds.size.width-20)/3 - 10, height: 30))
       statusLabel.font = UIFont.systemFont(ofSize: 13)
       statusLabel.textColor = UIColor.green
       statusLabel.textAlignment = NSTextAlignment.right
       return statusLabel
    }()
    
    public lazy var contentLabel:UILabel = {
        let la = UILabel()
        la.textColor = UIColor.lightGray
        la.numberOfLines = 0
        la.font = UIFont.systemFont(ofSize: 13)
        la.preferredMaxLayoutWidth = UIScreen.main.bounds.width - 20
        return la
    }()
}

